#include<iostream> 
#include<cstring>
using namespace std;
const int maxn = 105;
int dp[maxn][maxn],b[maxn],a[maxn];
int main(){
    int n;
    cin>>n;
    memset(dp,0x7f,sizeof dp);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i] = a[i]+b[i-1];
    }
    for(int i=1;i<=n;i++)	dp[i][i] = 0;
    
    for(int i=n;i>=1;i--){
        for(int j=i+1;j<=n;j++){
            for(int k=i;k<j;k++){
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+b[j]-b[i-1]);
            }
        }
    } 
    cout<<dp[1][n]<<endl;
    
    
}